<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%
String path = request.getContextPath();
%>
<jsp:include page="../../import.jsp" flush="true" />
<body>
<div class="searchSpan"></div>
<div  class="resultSpan"></div>

<div id="editDiv" title="用户编辑" style="display:none;height:100%">
	<span align='center' >
		<FORM METHOD='POST' id="userManageForm">
		<TABLE style="height:94%">
		<TR>
			<TD valign='top' >
			<INPUT TYPE="hidden" NAME="id"   id="id" value=''>
			<INPUT TYPE="hidden" NAME="index"   id="index" value=''>
			<INPUT TYPE="hidden" NAME="rid"   id="rid" value=''>
			<INPUT TYPE="hidden" NAME="gid"   id="gid" value=''>
			<TABLE >
			<TR >
					<TD >用户名：</TD>
					<TD><INPUT TYPE="text" NAME="name" id="name"  value=''></TD>
			</TR>
			<TR >
					<TD >登录名：</TD>
					<TD><INPUT TYPE="text" NAME="loginname" id="loginname"  value=''></TD>
			</TR>
				<TR  id="pwdInput" >
					<TD >密码：</TD>
					<TD><INPUT TYPE="password" NAME="password" id="password"  value=''></TD>
				</TR>

					<TR >
					<TD >基本信息：</TD>
					<TD><INPUT TYPE="text" NAME="info" id="info"  value=''></TD>
				</TR>
			</TABLE>
			</TD>
			<TD valign='top'>
				<jsp:include page="QD.roleTree.jsp" flush="true" >
					<jsp:param name="type" value="radio"/>
				</jsp:include>
			</TD>
		</TR>
		</TABLE>			
		</FORM>
	</span>
</div>
<!-- <TEXTAREA id="debug" ROWS="50" COLS="100"></TEXTAREA> -->

<SCRIPT LANGUAGE="JavaScript">
var tableParam = {
		div:'.resultSpan',
		css:'text-align:center;width:95%',
		queryParam:'index=quaryUsers&order=rid',
		title:null,pagination:'PAGE_NUMBER',
		isDownResult:false,
		elemt:{
			'用户名':{key:'NAME',order:true},
			'登陆名':{key:'LOGINNAME',order:true},
			'加密密码':{key:'PASSWORD',order:true},
			'用户角色':{key:'RID',order:true,method:function(data){return formatRoleName(data)}},
			'角色组':{key:'GNAME',order:true},
			'操作[<A HREF="javascript:addNewUser()">新增用户</A>]':{describe:function(rb){
					return '[<A HREF="#" id="tableDataEdit">修改</A>]/[<A HREF=\'javascript:delUser("'+rb["ID"]+'","'+rb["NAME"]+'")\'>删除</A>]';
			}}
		},bind:{
			'#tableDataEdit':{
				'click':function(rb){
					rb['INDEX'] = 'editUser';
					//rb['CTYPE'] = rb.RID;
					rb['RTYPE'] = rb.RID;
					infoView.showWithTable(rb);
					$('#pwdInput').attr('style','display:none');
					//setDtreeRadioValue(rb.RID);
				}	
			}
		}
	};

	QueryTable(tableParam);

	setSearch($('.searchSpan'),tableParam,{
		'NAME|LOGINNAME':{title:'用户或登录名'},
		'RID':{title:'用户角色',type:'select',data:{index:'quaryRoles',pid:'>0'},text:'NAME',value:'ID',
			method:function(key,value,queryTableParam){
				queryTableParam[key] = '%'+value+'%';
			}}
	});

	var infoView = new MoreInfoView("用户编辑",500,300,function(){
		_submit();
	});

	infoView.setContent($('#editDiv'));

	var _submit = function(){	
	var nameForm  = $('#loginname');
	if(nameForm.val()==''){
		alert("登录名必须输入！");
	}else{
		if($('#id').val()==''){
			var url = "<%=path%>/json/checkUser.action?userName="+nameForm.val()+"&$r"+Math.random();	
			$.getJSON(url, function(json){
				if(json.msg == 'true'){
					dataSend();
				}else{
					alert('登录名'+nameForm.val()+'已存在，请重新输入！');
					nameForm.focus();
					nameForm.val('');
				}
			});
		}else{
			dataSend();
		}
	}
}

var dataSend = function(){
	var data = infoView.toJson();
	data['rid'] = data['cType']==null?data['rType']:data['cType'];
	updateDB(data,function(r){
		infoView.close();
		if(r.json>0){
			QueryTable(tableParam);
		}
	});
}


var delUser = function(id,name){
	if(confirm('确定删除用户【'+name+'】?')){
		$('#id').val(id);
		$('#loginname').val('delete');
		$('#index').val('deleteUser');
		_submit();
	}
}
var addNewUser = function(){
	infoView.showWithTable({INDEX:'addUser'});
	$('#pwdInput').attr('style','display:""');
}

</SCRIPT>
</body>